home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / WINFONTS / WSFONT.ZIP / FM.BAS < prev    next >
BASIC Source File  |  1993-10-04  |  8KB  |  240 lines

  1. Option Explicit
  2. Option Compare Text
  3. Global MoveBasic%
  4. Global TestFont$
  5. Global CRLF$
  6. Global ActiveC As ListBox
  7. Type Logfont
  8.   lfHeight As Integer
  9.   lfWidth As Integer
  10.   lfEscapement As Integer
  11.   lfOrientation As Integer
  12.   lfWeight As Integer
  13.   lfItalic As String * 1
  14.   lfUnderline As String * 1
  15.   lfStrikeOut As String * 1
  16.   lfCharSet As String * 1
  17.   lfOutPrecision As String * 1
  18.   lfClipPrecision As String * 1
  19.   lfQuality As String * 1
  20.   lfPitchAndFamily As String * 1
  21.   lfFaceName As String * 32
  22. End Type
  23.  
  24. Type TextMetric
  25.   tmHeight As Integer
  26.   tmAscent As Integer
  27.   tmDescent As Integer
  28.   tmInternalLeading As Integer
  29.   tmExternalLeading As Integer
  30.   tmAveCharWidth As Integer
  31.   tmMaxCharWidth As Integer
  32.   tmWeight As Integer
  33.   tmItalic As String * 1
  34.   tmUnderlined As String * 1
  35.   tmStruckOut As String * 1
  36.   tmFirstChar As String * 1
  37.   tmLastChar As String * 1
  38.   tmDefaultChar As String * 1
  39.   tmBreakChar As String * 1
  40.   tmPitchAndFamily As String * 1
  41.   tmCharSet As String * 1
  42.   tmOverhang As Integer
  43.   tmDigitizedAspectX As Integer
  44.   tmDigitizedAspectY As Integer
  45. End Type
  46.  
  47. Global TM As TextMetric
  48. Global lf As Logfont
  49. Global LfArray(255) As Logfont
  50. Global TMArray(255) As TextMetric
  51. Global pFonts() As String
  52. Declare Function EnumFonts% Lib "GDI" (ByVal hDC%, ByVal lpFaceName As Any, ByVal lpFontFUnc&, ByVal lpData&)
  53. 'Declare Function GetObject% Lib "GDI" (ByVal hObject%, ByVal nCount%, ByVal lpObject&)
  54.  
  55. 'Declares for INI file routines
  56. Declare Function WritePrivateProfileString% Lib "KERNEL" (ByVal lpApplicationName$, ByVal lpKeyName$, ByVal lpString As Any, ByVal lplFileName$)
  57. Declare Function WriteProfileString% Lib "KERNEL" (ByVal lpApplicationName$, ByVal lpKeyName$, ByVal lpString As Any)
  58. Declare Function GetProfileInt% Lib "KERNEL" (ByVal lpAppName$, ByVal lpKeyName$, ByVal nDefault%)
  59. Declare Function GetPrivateProfileInt% Lib "KERNEL" (ByVal lpApplicationName$, ByVal lpKeyName$, ByVal nDefault%, ByVal lpFilename$)
  60. Declare Function GetPrivateProfileString% Lib "KERNEL" (ByVal lpApplicationName$, ByVal lpKeyName As Any, ByVal lpDefault$, ByVal lpReturnedString$, ByVal nSize%, ByVal lpFilename$)
  61. Declare Function GetProfileString% Lib "KERNEL" (ByVal lpAppName$, ByVal lpKeyName As Any, ByVal lpDefault$, ByVal lpReturnedString$, ByVal nSize%)
  62. Declare Function AddFontResource% Lib "GDI" (ByVal lpFilename As Any)
  63. Declare Function RemoveFontResource% Lib "GDI" (ByVal lpFilename As Any)
  64. Declare Function SendMessage% Lib "USER" (ByVal hWnd%, ByVal wMsg%, ByVal wParam%, lParam As Any)
  65. Const WM_FONTCHANGE = &H1D
  66. Const WM_WININICHANGE = &H1A
  67. 'Declares for GetSystemDir
  68. Declare Function GetSystemDirectory Lib "Kernel" (ByVal lpBuffer As String, ByVal nSize As Integer) As Integer
  69.  
  70. Sub BroadcastIniChange ()
  71. Dim y%
  72. y% = SendMessage(&H0, WM_FONTCHANGE, 0, 0)'tell other apps that font list has changed
  73. y% = SendMessage(&H0, WM_WININICHANGE, 0, 0)'tell other apps that WIN.INI has changed
  74.  
  75. End Sub
  76.  
  77. Sub DeletePrivIni (pApp$, pkey$, pFile$)
  78. Dim X%
  79. X% = WritePrivateProfileString%(pApp$, pkey$, 0&, pFile$)
  80. End Sub
  81.  
  82. Sub DeleteWinIni (pApp$, pkey$)
  83. Dim X%
  84. X% = WriteProfileString%(pApp$, pkey$, 0&)
  85. End Sub
  86.  
  87. Function Exists% (F$)
  88. '  * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  89. '  returns 0 if file not found, or if error in file spec,
  90. '  otherwise returns -1
  91. '  * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  92. On Error Resume Next
  93. Exists% = True
  94. If Len(Dir$(F$)) = 0 Then Exists% = False
  95. On Error GoTo 0
  96. End Function
  97.  
  98. Function GetPrivINI$ (pApp$, pkey$, pDefault$, pFile$)
  99. Dim X%
  100. Dim ret As String * 1024
  101. X% = GetPrivateProfileString%(pApp$, pkey$, pDefault$, ret, Len(ret), pFile$)
  102. If X% > 0 Then GetPrivINI$ = Left$(ret, X%)
  103. End Function
  104.  
  105. Function GetPrivIniInt% (pApp$, pkey$, pDefault%, pFile$)
  106. GetPrivIniInt% = GetPrivateProfileInt%(pApp$, pkey$, pDefault%, pFile$)
  107. End Function
  108.  
  109. Function GetSystemDir$ ()
  110. Dim Sys As String * 256, X%
  111. X = GetSystemDirectory(Sys, Len(Sys))
  112. 'X = InStr(1, Sys, Chr$(0))
  113. GetSystemDir$ = Left$(Sys, InStr(Sys, Chr$(0)) - 1) + "\"
  114. End Function
  115.  
  116. Function GetWinINI$ (pApp$, pkey$, pDefault$)
  117. Dim X%
  118. Dim ret As String * 1024
  119. X% = GetProfileString%(pApp$, pkey$, pDefault$, ret, Len(ret))
  120. If X% > 0 Then GetWinINI$ = Left$(ret, X%)
  121. End Function
  122.  
  123. Function GetWinIniInt% (pApp$, pkey$, pDefault%)
  124. GetWinIniInt% = GetProfileInt%(pApp$, pkey$, pDefault%)
  125. End Function
  126.  
  127. Function HIWORD% (LongVal&)
  128. HIWORD% = LongVal& \ 65536 ' (note: '\', not '/')
  129. End Function
  130.  
  131. Function Install% (fName$)
  132. Dim ret As String * 255
  133. Dim test$, y%
  134. test$ = GetPrivINI$("fonts", fName$, "uh-oh", "WSFONTS.INI")
  135. If test$ = "uh-oh" Then MsgBox "can't install " & fName$: Exit Function
  136. y% = AddFontResource(test$)   '  remove font resource for this file
  137. If y% <> 0 Then
  138.    PutWinIni "fonts", fName$, test$
  139.    DeletePrivIni "fonts", fName$, "WSFONTS.INI"
  140. Else
  141.    MsgBox "Couldn't install font."
  142. End If
  143. Install% = True
  144. End Function
  145.  
  146. Function ListPrivateIniEntries$ (pApp$, pFile$)
  147. Dim X%
  148. Dim ret As String * 4096
  149. X% = GetPrivateProfileString%(pApp$, 0&, "", ret, Len(ret), pFile$)
  150. If X% > 0 Then ListPrivateIniEntries$ = Left$(ret, X%)
  151. End Function
  152.  
  153. Function ListWinIniEntries$ (pApp$)
  154. Dim X%
  155. Dim ret As String * 4096
  156. X% = GetProfileString%(pApp$, 0&, "", ret, Len(ret))
  157. If X% > 0 Then ListWinIniEntries$ = Left$(ret, X%)
  158. End Function
  159.  
  160. Function LoWord% (LongVal&)
  161. LoWord% = LongVal& And 65535
  162. End Function
  163.  
  164. Sub PutPrivIni (pApp$, pkey$, pString$, pFile$)
  165. Dim X%
  166. X% = WritePrivateProfileString%(pApp$, pkey$, pString$, pFile$)
  167. End Sub
  168.  
  169. Sub PutWinIni (pApp$, pkey$, pString$)
  170. Dim X%
  171. X% = WriteProfileString%(pApp$, pkey$, pString$)
  172. End Sub
  173.  
  174. Function ReadFontInfo$ (ByVal F$)
  175. Dim fh%, A$, B$, lf%, X%, re%, test$
  176. fh% = FreeFile
  177. F$ = UCase$(F$)
  178.  
  179. If Not InStr(F$, "\") Then F$ = GetSystemDir$() & F$
  180. If Not InStr(F$, "FOT") > 0 Then ReadFontInfo$ = F$: Exit Function
  181. If Not Exists%(F$) Then MsgBox "Can't find" + F$
  182. lf% = FileLen(F$)
  183. ' Debug.Print F$; lf%
  184. Dim GetStuff As String * 5000
  185. Open F$ For Input As fh%
  186. On Error Resume Next
  187. GetStuff = Input$(lf%, #fh%)
  188. B$ = Left$(GetStuff, lf%)
  189. On Error GoTo 0
  190. Close fh%
  191. If Len(B$) < 260 Then MsgBox "Can't read " & F$: Exit Function
  192. B$ = Right$(B$, 260)
  193. For X% = 1 To Len(B$)
  194.    test$ = Mid$(B$, X%, 1)
  195.    If Asc(test$) > 31 And Asc(test$) < 127 Then
  196.       A$ = A$ + Mid$(B$, X%, 1)
  197.    End If
  198.    If Asc(test$) = 0 Then A$ = A$ + "|"
  199. Next
  200. 'trim v|'s
  201. X% = InStr(A$, "v|")
  202. Do While X%
  203.    A$ = Mid$(A$, X% + 2)
  204.    X% = InStr(A$, "v|")
  205. Loop
  206. 'TRIM LEADERS
  207. If X% > 0 Then A$ = Mid$(A$, X% + 2)
  208. Do While Left$(A$, 1) = "|"
  209.    A$ = Mid$(A$, 2)
  210. Loop
  211. 'trim trailers
  212. Do While Right$(A$, 1) = "|"
  213. A$ = Left$(A$, Len(A$) - 1)
  214. Loop
  215. 'should now read
  216. ReadFontInfo$ = A$
  217. End Function
  218.  
  219. Function UninStall% (ByVal fName$)
  220. Dim ret As String * 255
  221. Dim test$, y%
  222. test$ = GetWinINI$("fonts", fName$, "uh-oh")
  223. If test$ = "uh-oh" Then MsgBox "Can't uninstall " & fName$: Exit Function
  224. y% = RemoveFontResource(test$)   '  remove font resource for this file
  225. PutPrivIni "fonts", fName$, test$, "WSFONTS.INI"
  226. DeleteWinIni "fonts", fName$
  227. UninStall% = True
  228. End Function
  229.  
  230. Function UnsignedInt& (AA$)
  231. '   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  232. '   Convert string to unsigned int
  233. '   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  234. Dim Value&
  235. Value& = Asc(Right$(AA$, 1)) * 256&
  236. Value& = Value& + Asc(Left$(AA$, 1))
  237. UnsignedInt& = Value&
  238. End Function
  239.  
  240.